<?php
require_once APPLICATION_PATH . "/models/ModelBase.php";

class Views extends TT_Table_Abstract
{
    
    protected $_name = 'users';
    protected $_primary = 'uid';
    
        public function phong_ban_id($id)
            {
                 $db = $this->getSessionDB(); 
                 $sql="SELECT * FROM phong_ban WHERE id=?";
                 return $db->fetchAll($sql, array($id)); 
            }
   
      public function search($name,$phong_ban,$page,$page_rows) 
            {    $page=(int)$page;
                $page_rows=(int)$page_rows;
                 $db = $this->getSessionDB(); 
                 $sql="SELECT * FROM users_info WHERE name LIKE ? and phong_ban LIKE ?  LIMIT $page,$page_rows";
                 return $db->fetchAll($sql, array($name,$phong_ban));
            }
        
        public function num_search($name,$phong_ban) // lay tong so ket qua cua ham searh 2
            {
                 $db = $this->getSessionDB(); 
                 $sql="SELECT count(uid) as n FROM `users_info` WHERE `name` LIKE ? and `phong_ban` like ?";
                 return $db->fetchRow($sql,array($name,$phong_ban));
            }
    

        
      public function search2($name,$phong_ban,$page,$page_rows) // tim nguoi da thoi viec
        {
             $page=(int)$page;
             $page_rows=(int)$page_rows;
             $db = $this->getSessionDB(); 
             $sql="SELECT * FROM `users_info` WHERE date_out != 0 and `name` LIKE ? and `phong_ban` like ? limit $page ,$page_rows";
             return $db->fetchAll($sql,array($name,$phong_ban));
        }
        
       public function num_search2($name,$phong_ban) // lay tong so ket qua cua ham searh 2
        {
             $db = $this->getSessionDB(); 
             $sql="SELECT count(uid) as n2 FROM `users_info` WHERE date_out != 0 and `name` LIKE ? and `phong_ban` like ?";
             return $db->fetchRow($sql,array($name,$phong_ban));
        }
        
        public function search3($name,$phong_ban,$page,$page_rows)
        {
              $page=(int)$page;
             $page_rows=(int)$page_rows;
             $db = $this->getSessionDB(); 
               $sql="SELECT * FROM `users_info` WHERE date_out = 0 and `name` LIKE ? and `phong_ban` like ? limit $page ,$page_rows";
             return $db->fetchAll($sql,array($name,$phong_ban));
        }
        
         public function num_search3($name,$phong_ban) // lay tong so ket qua cua ham searh 3
        {
             $db = $this->getSessionDB(); 
             $sql="SELECT count(uid) as n3 FROM `users_info` WHERE date_out = 0 and `name` LIKE ? and `phong_ban` like ?";
             return $db->fetchRow($sql,array($name,$phong_ban));
        }
        
    
    public function checkInfo($uid)    
        {
           $db = $this->getSessionDB();
            $sql = 'SELECT * FROM users_info WHERE uid=? ';
            return $db->fetchRow($sql, array($uid));         
        }
    
     public function checkuid($username)
            {
               $db = $this->getSessionDB();
                $sql = 'SELECT uid FROM users WHERE name=? ';
                return $db->fetchRow($sql, array($username));         
            }
      public function checkusername($uid)
            {
               $db = $this->getSessionDB();
                $sql = 'SELECT name FROM users WHERE uid=? ';
                return $db->fetchRow($sql, array($uid));         
            }
}
